"""获取黄委许可决定和技术报告"""
# http://zw.yrcc.gov.cn/zwxxlist.jsp?bm=1120100


import requests
from bs4 import BeautifulSoup as bs
import re

# http://zw.yrcc.gov.cn/zwxxlist.jsp?bm=1120100&page=1
# http://zw.yrcc.gov.cn/zwxxlist.jsp?bm=1120100&page=1
r = requests.get('http://zw.yrcc.gov.cn/zwxxlist.jsp?bm=1120100&page=1')
data = r.text
soup = bs(r.text, 'html.parser')
font = soup.find(name='font', color='blue', string='1')
# for i in font:
mesagenum = int(font.previous_sibling.previous_sibling.text)
pagenum = int(soup.find_all(name='a', string=re.compile('\[[0-9]*\]'))[-1].text[1:-1])

# n = 1
n = pagenum
m = 0
for x in range(n):
    x = x + 1
    r = requests.get('http://zw.yrcc.gov.cn/zwxxlist.jsp?bm=1120100&page=%s' % x)
    # print(r.encoding)

    data = r.text
    soup = bs(r.text, 'html.parser')
    # print(data)
    # print(soup.prettify())

    #

    a = soup.find_all("a", target="_blank")
    for i in a:
        if i.find("font"):
            # print(i)
            name = i['title']
            href = 'http://zw.yrcc.gov.cn/' + i['href']
            time = i.parent.next_sibling.text[-10:]

            print(name)
            print(href)
            print(time)

            m = m + 1

if mesagenum == m:
    print('完成全部匹配，共匹配%s条信息' % m)
else:
    print('应匹配%s条信息，仅%s条信息' % (mesagenum, m))
